package com.techfengs.test17;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TestClient {//{{{
	public static void main (String[] args) throws IOException {//{{{
		System.out.println("客户端启动……");
		
		// => 创建套接字 ------------------------------------------------------------{{{
		Socket s = new Socket("172.20.110.53", 8888);
//}}}
		// => 创建流 ------------------------------------------------------------{{{
		OutputStream os = s.getOutputStream();
		DataOutputStream dos = new DataOutputStream(os);
		InputStream is = s.getInputStream();
		DataInputStream dis = new DataInputStream(is);
		//}}}
		// => 向服务器端发送数据 ------------------------------------------------------------{{{
		dos.writeUTF("你好，服务器，我是客户端");
//}}}
		// => 接收服务器的应答 ------------------------------------------------------------{{{
		String str = dis.readUTF();
		System.out.println("服务器对我说：" + str);
//}}}
		// => 关闭套接字 ------------------------------------------------------------{{{
		// 关闭流
		dos.close();
		os.close();
		dis.close();
		is.close();
		// 关闭套接字
		s.close();
//}}}
	}//}}}
}//}}}

